<?php namespace Cribbb\Services\Validators;
 
abstract class Validator 
{ 
	/**
	 * Array data wanting to validate
	 * @var array
	 */
	protected $input;
	
	/**
	 * Object store error messages
	 * @var Illuminate\Support\MessageBag
	 */
	protected $errors;
	
	/**
	 * Prepare data for validate
	 * 
	 * @param array $input which will be what we are wanting to validate
	 * @return void
	 */
	public function __construct($input = array())
	{
		$this->input = $input ?: \Input::all();
	}
	
	/**
	 * Perform the validation
	 * 
	 * @return boolean
	 */
	public function passes()
	{
		$validation = \Validator::make($this->input, static::$rules);
	
		if ($validation->passes()) {
			return true;
		}
		
		// If validation has failed, you may retrieve the error messages from the validator
		$this->errors = $validation->messages();
	
		return false;
	}
	
	/**
	 * Returns the $errors property because it is protected.
	 * 
	 * @return Illuminate\Support\MessageBag
	 */
	public function getErrors()
	{
		return $this->errors;
	}
 
}